package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * 执行DQL语句
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        try(
                Connection connection = DBUtil.getConnection();//继承自动关闭
        ){
            Statement statement = connection.createStatement();
            /*
            SELECT id,name,salary,title
            FROM teacher
            */
            String sql="SELECT id,name,salary,title\n" +
                    "            FROM teacher";
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                int salary = resultSet.getInt("salary");
                String title = resultSet.getString("title");
                System.out.println(id+"\t"+name+" "+salary+"\t"+title);
            }
            /*
            int num = statement.executeUpdate(sql);
            if(num>0){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }
             */
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
